use ggez::{glam::Vec2, graphics, mint::Point2};

use crate::animation::Animation;



pub struct Cannon {
    location: Vec2,
    direction: Vec2
}

impl Cannon {
    pub fn new(location: Vec2) -> Cannon {
        let direction = (Vec2{x: 400.0, y: 300.0} - location).normalize();
        Cannon { location, direction }
    }

    pub fn get_direction(&self) -> Vec2 {
        self.direction
    }
}

impl Animation for Cannon {
    fn update(&mut self, ctx: &mut ggez::Context) -> () {
        self.direction = (Vec2{x: ctx.mouse.position().x, y: ctx.mouse.position().y} - self.location).normalize();
    }

    fn display(&self, ctx: &mut ggez::Context, canvas : &mut ggez::graphics::Canvas) -> () {
        let line = graphics::Mesh::new_line(
            ctx, 
            &[Point2{x: 0.0, y: 0.0}, Point2{x: 20.0, y: 0.0}], 
            6.0, 
            graphics::Color::BLACK
        ).unwrap();
        canvas.draw(&line, graphics::DrawParam::default().dest(self.location).rotation(self.direction.y.asin()));
    }
}